<?php
	function __construct(){
		require './model/meinfo_model.php';
		$_GET['a']();
	}
	function index(){//显示用户信息
		if(isset($_SESSION['userInfo'])){
			$uid = $_SESSION['userInfo']['uid'];
			$ret = select("WHERE uid=$uid")[0];
			require './view/meinfo/index.php';
		}else{
			echo '您尚未登录!';
			echo "<meta http-equiv='refresh' content='1;./index.php?c=user&a=login'>";
		}
	}
	
	function change_info(){//修改信息界面
		$uid = $_SESSION['userInfo']['uid'];	
		$ret = select("WHERE uid=$uid")[0];
		require './view/meinfo/changeinfo.php';
	}
	function dochangeinfo(){//执行修改信息
		require './public/tools/fileUpload.php';
		require './public/tools/picZoom.php';
		$res = fileUpload(PIC_PATH,$_FILES['uface'],50,50);
		if($res['flag']){
			$_POST['uface'] = $res['picname'];
		}
		
		if($_POST['upwd']!=$_POST['upwd2']){
			echo '密码不一致,请点击<b style="color:deeppink;text-decoration:underline" onclick="history.go(-1)">返回</b>重新修改!';
			return;
		}
		
		if(empty($_POST['upwd']) || empty($_POST['upwd2'])){
			unset($_POST['upwd']);
		}else{
			$_POST['upwd'] = md5($_POST['upwd']);
		}
		unset($_POST['upwd2']);
		
		if($_POST['birth']==''){
			unset($_POST['birth']);
		}else{
			$_POST['birth'] = strtotime($_POST['birth']);
		}
		$_GET['id']=$_SESSION['userInfo']['uid'];
		if(update()){
			echo "<meta http-equiv='refresh' content='0;./index.php?c=meinfo&a=index'>";
		}else{
			echo '操作无效!您并没有改变该用户信息.';
			echo "<meta http-equiv='refresh' content='1;./index.php?c=meinfo&a=index'>";
		}
	}
	//------------
	function userdd(){
		$_GET['tblname'] = 'shop_orders';
		$_GET['pk'] = 'oid';
		$uid = $_SESSION['userInfo']['uid'];

		//分页处理-------------------------------------------
		
		$setRows = 6;           //每页条数
		$allRows = rowCount(" WHERE uid=$uid ");   //总条数
		$allPage = ceil($allRows/$setRows);//总页数
		
		$nowPage = empty($_GET['nowPage']) ? 1 : $_GET['nowPage'];//当前页
		
		$prevPage = $nowPage-1;
		$nextPage = $nowPage+1;
		
		if($prevPage < 1){
			$nowPage = 1;
			$prevPage = 1;
		}elseif($nextPage > $allPage){
			$nowPage = $allPage;
			$nextPage = $allPage;
		}

		$condition =' LIMIT '.(($nowPage-1)*$setRows).','.$setRows;
		//-----------------------------------------------
		$uid = $_SESSION['userInfo']['uid'];
		$ret = select("WHERE uid=$uid ".$condition);
		require './view/meinfo/userdd.php';
	}
	function deluserdd(){
		$_GET['tblname'] = 'shop_detail';
		$_GET['pk'] = 'oid';
		delete();
		$_GET['tblname'] = 'shop_orders';
		$_GET['pk'] = 'oid';
		delete();
		echo "<meta http-equiv='refresh' content='0;./index.php?c=meinfo&a=userdd'>";
	}
	
	function showmx(){
		$_GET['tblname'] = 'shop_detail';
		$_GET['pk'] = 'did';
		
		//分页处理-------------------------------------------
		
		$setRows = 10;           //每页条数
		$allRows = rowCount("WHERE oid=$_GET[id] ");   //总条数
		$allPage = ceil($allRows/$setRows);//总页数
		
		$nowPage = empty($_GET['nowPage']) ? 1 : $_GET['nowPage'];//当前页
		
		$prevPage = $nowPage-1;
		$nextPage = $nowPage+1;
		
		if($prevPage < 1){
			$nowPage = 1;
			$prevPage = 1;
		}elseif($nextPage > $allPage){
			$nowPage = $allPage;
			$nextPage = $allPage;
		}

		$condition =' LIMIT '.(($nowPage-1)*$setRows).','.$setRows;
		//-----------------------------------------------
		
		$ret = select("WHERE oid=$_GET[id] ".$condition);
		require './view/meinfo/showmx.php';
	}
	//---------------
	function ok(){
		$_GET['tblname'] = 'shop_orders';
		$_GET['pk'] = 'oid';
		$_POST['status'] = 3;
		update(" WHERE oid=$_GET[id]");
		echo "<meta http-equiv='refresh' content='0;./index.php?c=meinfo&a=userdd'>";
	}